<script setup>
import { onMounted, ref } from "vue";
//  按需引入 echarts
import * as echarts from "echarts";

onMounted(() => {
  init();
});
function init() {
  // 基于准备好的dom，初始化echarts实例
  var myChart = echarts.init(document.getElementById("main4"));
  // 指定图表的配置项和数据
  const waterMarkText = "ECHARTS";
  const canvas = document.createElement("canvas");
  const ctx = canvas.getContext("2d");
  canvas.width = canvas.height = 100;
  ctx.textAlign = "center";
  ctx.textBaseline = "middle";
  ctx.globalAlpha = 0.08;
  ctx.font = "20px Microsoft Yahei";
  ctx.translate(50, 50);
  ctx.rotate(-Math.PI / 4);
  ctx.fillText(waterMarkText, 0, 0);
  var option = {
    tooltip: {},
    backgroundColor: {
      type: "pattern",
      image: canvas,
      repeat: "repeat",
    },
    legend: {
      data: ["销量"],
    },
    xAxis: {
      data: ["衬衫", "羊毛333衫", "雪纺衫", "裤子", "高跟鞋", "袜子", "高跟鞋2", "袜子2"],
    },
    yAxis: {},
    series: [
      {
        name: "销量",
        type: "bar",
        data: [5, 20, 36, 10, 10, 20, 33, 22],
      },
    ],
  };
  // 使用刚指定的配置项和数据显示图表。
  myChart.setOption(option);
}
</script>

<template>
  <div class="echarts">
    <div id="main4" style="width: 1400px; height: 400px"></div>
  </div>
</template>

<style scoped>
.el-row {
  margin-bottom: 20px;
}
.el-row:last-child {
  margin-bottom: 0;
}
.el-col {
  border-radius: 4px;
}

.grid-content {
  border-radius: 4px;
  min-height: 36px;
  background: #d3dce6;
}
</style>
